package cn.ibizlab.odoo.core.odoo_stock.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint;
import cn.ibizlab.odoo.core.odoo_stock.domain.Stock_warehouse_orderpoint;
import cn.ibizlab.odoo.core.odoo_stock.filter.Stock_warehouse_orderpointSearchContext;
import cn.ibizlab.odoo.core.odoo_stock.service.IStock_warehouse_orderpointService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[最小库存规则] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Stock_warehouse_orderpointServiceImpl implements IStock_warehouse_orderpointService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Istock_warehouse_orderpointClientService stock_warehouse_orderpointClientService;

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //stock_warehouse_orderpointClientService.removeBatch(stock_warehouse_orderpoints) ;

    }

    @Override
    public void createBatch(List<Stock_warehouse_orderpoint> stock_warehouse_orderpoints, int batchSize) {

                        //stock_warehouse_orderpointClientService.createBatch(stock_warehouse_orderpoints,batchSize) ;

    }

    @Override
    public void updateBatch(List<Stock_warehouse_orderpoint> stock_warehouse_orderpoints, int batchSize) {

        //stock_warehouse_orderpointClientService.updateBatch(stock_warehouse_orderpoints,batchSize) ;

    }

    @Override
    public boolean update(Stock_warehouse_orderpoint stock_warehouse_orderpoint) {
        boolean bOk = false ;
        Istock_warehouse_orderpoint clientModel = this.convert2Model(stock_warehouse_orderpoint,null);
        stock_warehouse_orderpointClientService.update(clientModel) ;
        this.convert2Domain(clientModel,stock_warehouse_orderpoint) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public Stock_warehouse_orderpoint get(Integer id) {
        Istock_warehouse_orderpoint clientModel = stock_warehouse_orderpointClientService.createModel();
        clientModel.setId(id);
        stock_warehouse_orderpointClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Stock_warehouse_orderpoint get(Stock_warehouse_orderpoint stock_warehouse_orderpoint) {
        Stock_warehouse_orderpoint retstock_warehouse_orderpoint = this.get(stock_warehouse_orderpoint.getId()) ;
    	BeanCopier copier=BeanCopier.create(retstock_warehouse_orderpoint.getClass(), stock_warehouse_orderpoint.getClass(), false);
        copier.copy(retstock_warehouse_orderpoint, stock_warehouse_orderpoint, null);
        return stock_warehouse_orderpoint ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Istock_warehouse_orderpoint clientModel = stock_warehouse_orderpointClientService.createModel();
        clientModel.setId(id);
        stock_warehouse_orderpointClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean create(Stock_warehouse_orderpoint stock_warehouse_orderpoint) {
        boolean bOk = false ;
        Istock_warehouse_orderpoint clientModel = this.convert2Model(stock_warehouse_orderpoint,null);
        stock_warehouse_orderpointClientService.create(clientModel) ;
        this.convert2Domain(clientModel,stock_warehouse_orderpoint);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Stock_warehouse_orderpoint> searchDefault(Stock_warehouse_orderpointSearchContext context) {
        List<Stock_warehouse_orderpoint> list = new ArrayList<Stock_warehouse_orderpoint>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint> clientModelList = stock_warehouse_orderpointClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_warehouse_orderpoint>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据产品查询
     */
    @Override
    public Page<Stock_warehouse_orderpoint> selectByOdoo_product(Integer id){
        Stock_warehouse_orderpointSearchContext context = new Stock_warehouse_orderpointSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_warehouse_orderpoint> list = new ArrayList<Stock_warehouse_orderpoint>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint> clientModelList = stock_warehouse_orderpointClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_warehouse_orderpoint>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据公司查询
     */
    @Override
    public Page<Stock_warehouse_orderpoint> selectByOdoo_company(Integer id){
        Stock_warehouse_orderpointSearchContext context = new Stock_warehouse_orderpointSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_warehouse_orderpoint> list = new ArrayList<Stock_warehouse_orderpoint>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint> clientModelList = stock_warehouse_orderpointClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_warehouse_orderpoint>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Stock_warehouse_orderpoint> selectByOdoo_create(Integer id){
        Stock_warehouse_orderpointSearchContext context = new Stock_warehouse_orderpointSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_warehouse_orderpoint> list = new ArrayList<Stock_warehouse_orderpoint>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint> clientModelList = stock_warehouse_orderpointClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_warehouse_orderpoint>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Stock_warehouse_orderpoint> selectByOdoo_write(Integer id){
        Stock_warehouse_orderpointSearchContext context = new Stock_warehouse_orderpointSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_warehouse_orderpoint> list = new ArrayList<Stock_warehouse_orderpoint>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint> clientModelList = stock_warehouse_orderpointClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_warehouse_orderpoint>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据库存位置查询
     */
    @Override
    public Page<Stock_warehouse_orderpoint> selectByOdoo_location(Integer id){
        Stock_warehouse_orderpointSearchContext context = new Stock_warehouse_orderpointSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_warehouse_orderpoint> list = new ArrayList<Stock_warehouse_orderpoint>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint> clientModelList = stock_warehouse_orderpointClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_warehouse_orderpoint>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据仓库查询
     */
    @Override
    public Page<Stock_warehouse_orderpoint> selectByOdoo_warehouse(Integer id){
        Stock_warehouse_orderpointSearchContext context = new Stock_warehouse_orderpointSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_warehouse_orderpoint> list = new ArrayList<Stock_warehouse_orderpoint>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint> clientModelList = stock_warehouse_orderpointClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_warehouse_orderpoint clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_warehouse_orderpoint>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Istock_warehouse_orderpoint convert2Model(Stock_warehouse_orderpoint domain , Istock_warehouse_orderpoint model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = stock_warehouse_orderpointClientService.createModel() ;
        }

         if(domain.getActiveDirtyFlag())
            model.setActive(domain.getActive());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getLead_daysDirtyFlag())
            model.setLead_days(domain.getLead_days());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getLead_typeDirtyFlag())
            model.setLead_type(domain.getLead_type());
         if(domain.getGroup_idDirtyFlag())
            model.setGroup_id(domain.getGroup_id());
         if(domain.getProduct_max_qtyDirtyFlag())
            model.setProduct_max_qty(domain.getProduct_max_qty());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getQty_multipleDirtyFlag())
            model.setQty_multiple(domain.getQty_multiple());
         if(domain.getProduct_min_qtyDirtyFlag())
            model.setProduct_min_qty(domain.getProduct_min_qty());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getWarehouse_id_textDirtyFlag())
            model.setWarehouse_id_text(domain.getWarehouse_id_text());
         if(domain.getProduct_id_textDirtyFlag())
            model.setProduct_id_text(domain.getProduct_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getProduct_uomDirtyFlag())
            model.setProduct_uom(domain.getProduct_uom());
         if(domain.getCompany_id_textDirtyFlag())
            model.setCompany_id_text(domain.getCompany_id_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getLocation_id_textDirtyFlag())
            model.setLocation_id_text(domain.getLocation_id_text());
         if(domain.getLocation_idDirtyFlag())
            model.setLocation_id(domain.getLocation_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getWarehouse_idDirtyFlag())
            model.setWarehouse_id(domain.getWarehouse_id());
         if(domain.getProduct_idDirtyFlag())
            model.setProduct_id(domain.getProduct_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
        return model ;
    }

    public Stock_warehouse_orderpoint convert2Domain( Istock_warehouse_orderpoint model ,Stock_warehouse_orderpoint domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Stock_warehouse_orderpoint();
        }

        if(model.getActiveDirtyFlag())
            domain.setActive(model.getActive());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getLead_daysDirtyFlag())
            domain.setLead_days(model.getLead_days());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getLead_typeDirtyFlag())
            domain.setLead_type(model.getLead_type());
        if(model.getGroup_idDirtyFlag())
            domain.setGroup_id(model.getGroup_id());
        if(model.getProduct_max_qtyDirtyFlag())
            domain.setProduct_max_qty(model.getProduct_max_qty());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getQty_multipleDirtyFlag())
            domain.setQty_multiple(model.getQty_multiple());
        if(model.getProduct_min_qtyDirtyFlag())
            domain.setProduct_min_qty(model.getProduct_min_qty());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getWarehouse_id_textDirtyFlag())
            domain.setWarehouse_id_text(model.getWarehouse_id_text());
        if(model.getProduct_id_textDirtyFlag())
            domain.setProduct_id_text(model.getProduct_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getProduct_uomDirtyFlag())
            domain.setProduct_uom(model.getProduct_uom());
        if(model.getCompany_id_textDirtyFlag())
            domain.setCompany_id_text(model.getCompany_id_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getLocation_id_textDirtyFlag())
            domain.setLocation_id_text(model.getLocation_id_text());
        if(model.getLocation_idDirtyFlag())
            domain.setLocation_id(model.getLocation_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getWarehouse_idDirtyFlag())
            domain.setWarehouse_id(model.getWarehouse_id());
        if(model.getProduct_idDirtyFlag())
            domain.setProduct_id(model.getProduct_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        return domain ;
    }


}
